package ar.pmt.gwt.client.recurso.view;

import ar.pmt.gwt.client.common.view.PmtGwtView;
import ar.pmt.gwt.client.core.ConstantesGwt;
import ar.pmt.gwt.client.core.MethodRequest;
import ar.pmt.gwt.client.recurso.store.RecursoDataSource;
import ar.pmt.vista.beans.PaginacionBean;
import ar.pmt.vista.beans.RecursoBean;
import ar.pmt.vista.beans.StringBean;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourcePasswordField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.DSDataFormat;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.HeaderItem;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.VLayout;

/**
 * @author gburgener
 * View de ALTA-MODIFICACION de RECURSOS
 *
 */
public class AltaModificacionRecursoViewSmart extends PmtGwtView {
		
	
	 
		
		
	
	
	/**
	 * Configuracion de componentes de las vista
	 */
	AltaModificacionRecursoViewSmart(){
		
		
    	
 
     	
        
        final DynamicForm form = new DynamicForm();  
      	
      	form.setDataSource(RecursoDataSource.getInstance("//localhost:8031/PMT-GWT/pmtJson"));  
		form.setUseAllDataSourceFields(true);  
		
		HeaderItem header = new HeaderItem();  
		header.setDefaultValue("Alta/Modificacion Recurso");
		
		
		IButton loadButton = new IButton("Load");  
			loadButton.addClickHandler(new ClickHandler() {  
		             public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {  
		                 if(form.validate()) { 
		                	 MethodRequest methodRequest = new MethodRequest("ar.pmt.vista.manager.RecursoManager","obtenerRecurso");
		                  	 methodRequest.agregarClasesArgumento(StringBean.class); 
		                  	 methodRequest.agregarAtributos(StringBean.getValorID(), "74009");
		                	 form.setAction("//localhost:8031/PMT-GWT/pmtJson"+methodRequest.toRequestUrl());
			                 form.submit();
		                 }  
		             }  
		         }); 
			
			
		IButton saveButton = new IButton("Save");  
		saveButton.addClickHandler(new ClickHandler() {  
	             public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {  
	                 if(form.validate()) { 
	                	 
	                	 MethodRequest methodRequest = new MethodRequest("ar.pmt.vista.manager.RecursoManager","guardarRecurso");
	                 	 methodRequest.agregarClasesArgumento(RecursoBean.class);
	                	 form.setAction("//localhost:8031/PMT-GWT/pmtJson"+methodRequest.toRequestUrl());
		                 form.submit();
	                 }  
	             }  
	         }); 
		   
		
		 form.setFields(header);
		 
		 
		 
		 ///
		  final Window window = new Window();  
		          window.setAutoSize(true);  
		          window.setTitle("Buscador Rapido");  
		          window.setWidth(500);  
		          window.setHeight(600);    
		          window.setCanDragReposition(true);  
		          window.setCanDragResize(true);  
		          
		          ///
		          
		      	MethodRequest methodRequest = new MethodRequest("ar.pmt.vista.manager.RecursoManager","obtenerRecursos");
				methodRequest.agregarClasesArgumento(RecursoBean.class);
				methodRequest.agregarClasesArgumento(PaginacionBean.class);
				
				methodRequest.agregarAtributos(PaginacionBean.getPrimerResultadoID(), "0");
				methodRequest.agregarAtributos(PaginacionBean.getResultadosMaximoID(), "20");
				methodRequest.setTemplateOut(ConstantesGwt.TEMPLATE_DEFAULT);
		      	 DataSource dataSource = new DataSource();  
		           dataSource.setDataFormat(DSDataFormat.JSON); 
		          dataSource.setDataURL("//localhost:8031/PMT-GWT/pmtJson"+methodRequest.toRequestUrl());  
		          DataSourceTextField userNameField = new DataSourceTextField(RecursoBean.getUnicoIdID(), "Username", 50, true);  
		          DataSourceTextField firstNameField = new DataSourceTextField(RecursoBean.getNombreID(), "First Name", 50, true);  
		          DataSourceTextField lastNameField = new DataSourceTextField(RecursoBean.getApellidoID(), "Last Name", 50, true);  
		          DataSourceTextField emailField = new DataSourceTextField(RecursoBean.getEmailID(), "Email", 100, true); 
		          
		                 ListGrid countryGrid = new ListGrid(); 
		                // countryGrid.setDataPageSize(2);
		                   countryGrid.setWidth(300);  
		                   countryGrid.setHeight(600);  
		                   countryGrid.setAlternateRecordStyles(true);  
		                   
		                   
		              
		                   
		                   countryGrid.setDataSource(dataSource);  
		             
		                  
		                   ListGridField unicoIdField = new ListGridField(RecursoBean.getUnicoIdID(), "User");  
		                   ListGridField nombreField = new ListGridField(RecursoBean.getNombreID(), "Nombre");  
		                   ListGridField apellidoField = new ListGridField(RecursoBean.getApellidoID(), "Apellido");  
		             
		                   countryGrid.setFields(unicoIdField, nombreField, apellidoField);  
		             
		                   countryGrid.setAutoFetchData(true);  
		                   countryGrid.setShowFilterEditor(true); 
		                   
		                   window.addChild(countryGrid);
		 
		 ///
		      	IButton openButton = new IButton("Open");  
		      	openButton.addClickHandler(new ClickHandler() {  
			             public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {  
			               
			            	 window.show();
			                
			             }  
			         });       
		    
		
		 VLayout layout = new VLayout(10);  
	        layout.addMember(form);  
	        layout.addMember(loadButton);
	        layout.addMember(saveButton);
	        layout.addMember(openButton);
	        initWidget(layout);
	
	}
	
	public void control(){
		
	}
	/**
	 * Stores de Vista
	 */
	public void store() {
	
	}

	@Override
	public void configView() {
		// TODO Auto-generated method stub
		
	}

	
	

	
}
